<?php
// +-------------------------------------------------------------------------------
// | DingZone [ A Rapid Development Framework For Dingtalk ]
// +-------------------------------------------------------------------------------
// | 站点模块配置 v1.0
// |
// | Copyright (c) 2014-2018 http://www.heimalanshi.com All rights reserved.
// | Author : Jie
// | Date : 2018-08-09
// +-------------------------------------------------------------------------------

namespace app\core\model;

use think\Model;

class SiteModuleConfig extends Model {
    /**
     * 增加模块可配置选项
     *
     * @param $mid
     * @param $configs
     */
    public static function createConfigs($mid, $configs) {
        foreach ($configs as $config) {
            $data = [
                'module_id' => $mid,
                'title' => $config['title'],
                'key' => $config['key'],
                'type' => $config['type'],
                'defaultval' => $config['defaultval'],
                'tip' => $config['tip'],
                'param' => json_encode($config['param'])
            ];
            self::create($data);
        }
    }

    /**
     * 获取模块所有的可配置选项
     *
     * @param $mid
     * @return false|static[]
     * @throws \think\exception\DbException
     */
    public static function getConfigs($mid) {
        return self::all([
            'module_id' => $mid
        ]);
    }

    /**
     * 删除模块相关的全部菜单和入口
     *
     * @param $mid
     * @return int
     */
    public static function deleteByMid($mid) {
        $query = new self();
        return $query->where(['module_id' => $mid])->delete();
    }
}